package com.wythe.mall.adapter;

import android.content.Context;
import android.support.v7.widget.AppCompatCheckBox;
import android.support.v7.widget.AppCompatImageView;
import android.support.v7.widget.AppCompatTextView;
import android.support.v7.widget.LinearLayoutCompat;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.wythe.mall.R;

import java.util.ArrayList;

import top.yokey.base.base.BaseViewHolder;
import top.yokey.base.bean.CartBean;

public class CartListAdapter extends RecyclerView.Adapter<CartListAdapter.ViewHolder> {

//    private final ArrayList<CartBean> arrayList;
    private OnItemClickListener onItemClickListener;
    private Context context;

    public CartListAdapter(Context context,ArrayList<CartBean> arrayList) {
//        this.arrayList = arrayList;
        this.context = context;
        this.onItemClickListener = null;
    }

    @Override
    public int getItemCount() {

        return 2;

    }

    @Override
    public void onBindViewHolder(final ViewHolder holder, int position) {

//        final int positionInt = position;
//        final CartBean bean = arrayList.get(position);
        final GoodsCartListAdapter goodsCartListAdapter;

//        holder.storeNameTextView.setText(bean.getStoreName());
//        holder.mainCheckBox.setChecked(bean.isCheck());

//        goodsCartListAdapter = new GoodsCartListAdapter(null);
//        LinearLayoutManager linearLayoutManager = new LinearLayoutManager(context);
//        linearLayoutManager.setOrientation(LinearLayoutManager.VERTICAL);
//        holder.mainRecyclerView.setLayoutManager(linearLayoutManager);
//        holder.mainRecyclerView.setAdapter(goodsCartListAdapter);
//        BaseApplication.get().setRecyclerView(BaseApplication.get(), holder.mainRecyclerView, goodsCartListAdapter);

//        if (bean.getMansong() == null || bean.getMansong().size() == 0) {
            holder.mansongLineView.setVisibility(View.GONE);
            holder.manSongLinearLayout.setVisibility(View.GONE);
//        } else {
//            holder.mansongLineView.setVisibility(View.VISIBLE);
//            holder.manSongLinearLayout.setVisibility(View.VISIBLE);
//            holder.manSongDescTextView.setText(bean.getMansong().get(0).getDesc());
//            BaseImageLoader.get().display(bean.getMansong().get(0).getUrl(), holder.manSongGoodsImageView);
//        }

//        goodsCartListAdapter.setOnItemClickListener(new GoodsCartListAdapter.OnItemClickListener() {
//            @Override
//            public void onClick(int position, CartBean.GoodsBean goodsBean) {
//                if (onItemClickListener != null) {
//                    onItemClickListener.onGoods(positionInt, position, goodsBean);
//                }
//            }
//
//            @Override
//            public void onDelete(int position, CartBean.GoodsBean goodsBean) {
//                if (onItemClickListener != null) {
//                    onItemClickListener.onGoodsDelete(positionInt, position, goodsBean);
//                }
//            }
//
//            @Override
//            public void onAdd(int position, CartBean.GoodsBean goodsBean) {
//                if (onItemClickListener != null) {
//                    onItemClickListener.onGoodsAdd(positionInt, position, goodsBean);
//                }
//            }
//
//            @Override
//            public void onSub(int position, CartBean.GoodsBean goodsBean) {
//                if (onItemClickListener != null) {
//                    onItemClickListener.onGoodsSub(positionInt, position, goodsBean);
//                }
//            }
//
//            @Override
//            public void onCheck(int position, boolean isCheck, CartBean.GoodsBean goodsBean) {
//                if (onItemClickListener != null) {
//                    onItemClickListener.onGoodsCheck(positionInt, position, isCheck, goodsBean);
//                }
//            }
//        });
//
//        holder.mainCheckBox.setOnClickListener(new View.OnClickListener() {
//            @Override
//            public void onClick(View v) {
//                if (onItemClickListener != null) {
//                    onItemClickListener.onCheck(positionInt, holder.mainCheckBox.isChecked(), bean);
//                }
//            }
//        });
//
//        holder.storeLinearLayout.setOnClickListener(new View.OnClickListener() {
//            @Override
//            public void onClick(View v) {
//                if (onItemClickListener != null) {
//                    onItemClickListener.onStore(positionInt, bean);
//                }
//            }
//        });
//
//        holder.mainLinearLayout.setOnClickListener(new View.OnClickListener() {
//            @Override
//            public void onClick(View v) {
//                if (onItemClickListener != null) {
//                    onItemClickListener.onClick(positionInt, bean);
//                }
//            }
//        });

    }

    @Override
    public ViewHolder onCreateViewHolder(ViewGroup group, int viewType) {
        View view = LayoutInflater.from(group.getContext()).inflate(R.layout.item_list_cart, group, false);
        return new ViewHolder(view);
    }

    public void setOnItemClickListener(OnItemClickListener listener) {

        this.onItemClickListener = listener;

    }

    public interface OnItemClickListener {

        void onClick(int position, CartBean bean);

        void onStore(int position, CartBean bean);

        void onCheck(int position, boolean isCheck, CartBean bean);

        void onGoods(int position, int positionGoods, CartBean.GoodsBean bean);

        void onGoodsDelete(int position, int positionGoods, CartBean.GoodsBean bean);

        void onGoodsAdd(int position, int positionGoods, CartBean.GoodsBean bean);

        void onGoodsSub(int position, int positionGoods, CartBean.GoodsBean bean);

        void onGoodsCheck(int position, int positionGoods, boolean isCheck, CartBean.GoodsBean bean);

    }

    class ViewHolder extends RecyclerView.ViewHolder {

        private LinearLayoutCompat mainLinearLayout;
        private LinearLayoutCompat storeLinearLayout;
        private AppCompatCheckBox mainCheckBox;
        private AppCompatTextView storeNameTextView;

        private View mansongLineView;
        private LinearLayoutCompat manSongLinearLayout;
        private AppCompatTextView manSongDescTextView;
        private AppCompatImageView manSongGoodsImageView;

        private RecyclerView mainRecyclerView;

        private ViewHolder(View view) {
            super(view);
            mainLinearLayout = (LinearLayoutCompat) view.findViewById(R.id.mainLinearLayout);
            storeLinearLayout = (LinearLayoutCompat) view.findViewById(R.id.storeLinearLayout);
            mainCheckBox = (AppCompatCheckBox) view.findViewById(R.id.mainCheckBox);
            storeNameTextView = (AppCompatTextView) view.findViewById(R.id.storeNameTextView);
            mansongLineView = view.findViewById(R.id.mansongLineView);
            manSongLinearLayout = (LinearLayoutCompat) view.findViewById(R.id.manSongLinearLayout);
            manSongDescTextView = (AppCompatTextView) view.findViewById(R.id.manSongDescTextView);
            manSongGoodsImageView = (AppCompatImageView) view.findViewById(R.id.manSongGoodsImageView);
            mainRecyclerView = (RecyclerView) view.findViewById(R.id.mainRecyclerView);

        }

    }

}
